/*
 * Copyright (c) 2005 Infoservice, Inc. All  Rights Reserved.
 * This software is published under the terms of the Infoservie Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * @File name:      MD5Encrypt.java
 * @Create on:      2005-4-19    
 * @Author :        Administrator
 * 
 * @ChangeList
 * ---------------------------------------------------
 * Date			Editor				ChangeReasons
 *
 */
package com.yonyou.gmmc.dealerApp.api.entity;

import java.security.MessageDigest;

/**
 * @Description :
 */
public class MD5Encrypt {

    /**
     * 
     * MD5加密
     *
     * @author WangHuicheng
     * @date 2016年11月18日
     * @param sourceString
     * @return
     */
    public static String MD5Encode(String sourceString) {
        String resultString = null;
        try {
            resultString = new String(sourceString);
            MessageDigest md = MessageDigest.getInstance("MD5");
            resultString = byte2hexString(md.digest(resultString.getBytes()));
        } catch (Exception ex) {
        }
        return resultString;
    }

    public static final String byte2hexString(byte[] bytes) {
        StringBuffer buf = new StringBuffer(bytes.length * 2);
        for (int i = 0; i < bytes.length; i++) {
            if ((bytes[i] & 0xff) < 0x10) {
                buf.append("0");
            }
            buf.append(Long.toString(bytes[i] & 0xff, 16));
        }
        return buf.toString();
    }

}
